<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Generates a key</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.mhash-get-hash-name.html">« mhash_get_hash_name</a></li>
      <li style="float: right;"><a href="function.mhash.html">mhash »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.mhash.html">Mhash 函数</a></li>
    <li>Generates a key</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.mhash-keygen-s2k" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mhash_keygen_s2k</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">mhash_keygen_s2k</span> &mdash; <span class="dc-title">Generates a key</span></p>

 </div>

 <div id="function.mhash-keygen-s2k-refsynopsisdiv">
  <div class="warning"><strong class="warning">警告</strong><p class="simpara">此函数自 PHP 8.1.0 
起<em class="emphasis">弃用</em>。强烈建议不要应用此函数。</p></div>
 </div>
 
 <div class="refsect1 description" id="refsect1-function.mhash-keygen-s2k-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mhash_keygen_s2k</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$algo</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$password</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$salt</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$length</code></span><br>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   Generates a key according to the given <code class="parameter">algo</code>, using an user
   provided <code class="parameter">password</code>.
  </p>
  <p class="para">
   This is the Salted S2K algorithm as specified in the OpenPGP
   document (<a href="http://www.faqs.org/rfcs/rfc2440" class="link external">&raquo;&nbsp;RFC 2440</a>).
  </p>
  <p class="para">
   Keep in mind that user supplied passwords are not really suitable
   to be used as keys in cryptographic algorithms, since users normally
   choose keys they can write on keyboard. These passwords use
   only 6 to 7 bits per character (or less). It is highly recommended
   to use some kind of transformation (like this function) to the user
   supplied key.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mhash-keygen-s2k-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">algo</code></dt>

     <dd>

      <p class="para">
       The hash ID used to create the key.
       One of the <strong><code>MHASH_hashname</code></strong> constants.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">password</code></dt>

     <dd>

      <p class="para">
       An user supplied password.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">salt</code></dt>

     <dd>

      <p class="para">
       Must be different and random enough for every key you generate in
       order to create different keys. Because <code class="parameter">salt</code>
       must be known when you check the keys, it is a good idea to append
       the key to it. Salt has a fixed length of 8 bytes and will be padded
       with zeros if you supply less bytes.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">length</code></dt>

     <dd>

      <p class="para">
       The key length, in bytes.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mhash-keygen-s2k-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the generated key as a string, or <strong><code>false</code></strong> on error.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.mhash-keygen-s2k-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.1.0</td>
       <td>
        This function has been deprecated.
        Use the <a href="ref.hash.html" class="link"><code class="literal">hash_*()</code> functions</a> instead.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

 
</div></div></div></body></html>